﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SIPO.Web.Support;

using SIPO.Library.DomainObject.Administration;
using SIPO.Library.DataAccess.Administration;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.DataAccess.Transaction;
using System.Configuration;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;


namespace SIPO.Web.Forms.Transaction
{
    public partial class recExpenseform : BasePage
    {
        private int id = -1;
        protected override void OnLoad(EventArgs e)
        {
            if (Request.Params["id"] != null)
            {
                id = Convert.ToInt32(Request.Params["id"]);
            }
         
            if (!Page.IsPostBack)
            {
                
                recAlocationRepo recAlocationDal = new recAlocationRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                recExpenseRepo recExpenseDal = new recExpenseRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
               
                List<recAlocation> Alocation = recAlocationDal.GetList();
                ddlAlocation.Items.Clear();
                Alocation.ForEach(delegate(recAlocation alocation)
                {
                    ddlAlocation.Items.Add(new ListItem(alocation.AlocationCode+" - "+alocation.AlocationName,alocation.AlocationID.ToString()));
                });
                ddlAlocation.Items.Insert(0, new ListItem("-- pilih alokasi --",""));
                if (id >= 0)
                {
                    recExpense recexpense = recExpenseDal.GetById(id);
                                    
                        var a  = recexpense.TransDate.ToString("dd MMM yyyy");
                        var b = a.Substring(3, 3);
                        switch (b)
                        {
                            case ("Des"):
                                a = a.Replace("Des", "Dec");
                                break;
                            case ("Peb"):
                                a = a.Replace("Peb", "Feb");
                                break;
                            case ("Mei"):
                                a = a.Replace("Mei", "May");
                                break;
                            case ("Agu"):
                                a = a.Replace("Agu", "Aug");
                                break;
                            case ("Nop"):
                                a = a.Replace("Nop", "Nov");
                                break;
                            case ("Okt"):
                                a = a.Replace("Okt", "Oct");
                                break;
                            default:
                                // do nothing
                                break;

                        }
                        txtTransDate.Text = a;
                    txtInvoiceNo.Text = recexpense.TransNo;
                    txtTujuan.Text = recexpense.TransDesc;
                    txtValue.Text = Convert.ToDecimal(recexpense.TransValues).ToString().Replace(".00","");
                    ddlAlocation.SelectedValue = recexpense.TransAlocationID;
                    txtAlokasi.Text = recexpense.TransAlocationName;
                    hfID.Value = recexpense.ExpenseID.ToString();
                    hfAlocationName.Value = ddlAlocation.SelectedItem.ToString().Replace('-', ',');
                }
            }
        }
    }
}